package com.sc.sc250601.cook.controller;

import com.sc.sc250601.cook.pojo.BrowseRecord;
import com.sc.sc250601.cook.pojo.RecipeBrowseDTO;
import com.sc.sc250601.cook.pojo.Result;
import com.sc.sc250601.cook.service.BrowseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/browseRecord")
public class BrowseRecordController {
    @Autowired
    private BrowseRecordService browseRecordService;

    /**
     * 添加浏览记录
     */
    @RequestMapping("/recordBrowseRecord")
    public Result recordBrowseRecord(@RequestBody BrowseRecord record) {
        int result = browseRecordService.recordBrowse(record);
        if (result != 0) {
            return new Result(1, "添加浏览记录成功");
        }
        return new Result(0, "添加浏览记录失败");
    }

    /**
     * 获取用户菜谱浏览记录
     */
    @RequestMapping("/getRecipeRecordByUserId")
    public Result getRecipeRecordByUserId(Long userId) {
        List<RecipeBrowseDTO> browseRecordList = browseRecordService.getBrowseRecordByUserId(userId);
        return browseRecordList.isEmpty() ?
                new Result(0, "暂无浏览记录") :
                new Result(1, "浏览记录查询成功", browseRecordList);

    }
}
